from scipy import integrate

# 定积分是求一个函数的图形在一个闭区间上和 x 坐标轴围成的面积

def f(x):
    y = x + 1
    return y

v, err = integrate.quad(f, -1, 1) #(计算范围)修改此处时，同时修改plt显示范围 x = np.linspace(-1, 1, 100)
print(v)


# 可视化
import numpy as np, matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.axes3d import Axes3D

fig, ax = plt.subplots(figsize=(8, 3))
x = np.linspace(-1, 1, 100) #(显示范围, 步长)
ax.plot(x, f(x))
ax.fill_between(x, f(x), color='green', alpha=0.5)
ax.set_ylim(0, 25)
plt.show()